package tableRelations.dao;

import java.util.List;

import javax.persistence.Query;

import org.hibernate.Session;


import tableRelations.entity.Student;

public class StudentDAO {
	private Session session=HibernateUtils.getSession();
	
	public List<Student> findAll(){
		String hql="from Student";
		Query query = session.createQuery(hql);
		return query.getResultList();
	}
	
	public void save(Student model) {
		session.persist(model);
	}
	
	public void deleteById(Integer id) {
		String hql="delete Student t where t.id=?";
		Query query=session.createQuery(hql);
		query.setParameter(0, id);
		query.executeUpdate();
	}
	
	public Student findById(Integer id) {
		Student student = session.get(Student.class, id);
		return student;
	}
}
